/**
 * 
 */
package com.yullage.ann.core;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Yu-chun Huang
 * 
 */
public class Layer {

	private static int counter = 0;
	public final int id; // auto increment, starts at 0

	private List<Neuron> neurons = new ArrayList<Neuron>();

	private List<Layer> inLayers = new ArrayList<Layer>();
	private Map<Integer, Layer> inLayerLookup = new HashMap<Integer, Layer>();

	public Layer(int numNeurons, boolean isAddBiasNeuron) {
		id = counter;
		counter++;

		for (int i = 0; i < numNeurons; i++) {
			Neuron neuron = new NormalNeuron();

			if (isAddBiasNeuron) {
				neuron.addInNeuron(BiasNeuron.getInstance());
			}

			neurons.add(neuron);
		}
	}

	public List<Neuron> getNeurons() {
		return neurons;
	}

	public void addInLayer(List<Layer> layers) {
		for (Layer layer : layers) {
			addInLayer(layer);
		}
	}

	public void addInLayer(Layer layer) {
		inLayers.add(layer);
		inLayerLookup.put(layer.id, layer);

		for (Neuron neuron : neurons) {
			neuron.addInNeuron(layer.getNeurons());
		}
	}

	public List<Double> getOutputVector() {
		List<Double> vector = new ArrayList<Double>();

		for (Neuron neuron : neurons) {
			vector.add(neuron.getOutput());
		}

		return vector;
	}

}
